﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Win32;


namespace GolfScoringApplication
{
    public enum AddressType
    {
        Home,
        Work,
        Other
    }

    public enum FormType
    {
        Golfer
    }

    public class Address
    {
        private AddressType _Type;
        private string _AddressOne;
        private string _AddressTwo;
        private string _AddressThree;
        private string _City;
        private string _State;
        private string _ZipCode;
        private string _Name;

        public string Name
        {
            get { return _Name; }
        }

        public AddressType Type
        {
            get  { return _Type; }
        }

        public string AddressOne
        {
            get { return _AddressOne;}
        }

        public string AddressTwo
        {
            get{return _AddressTwo;}
        }

        public string AddressThree
        {
            get{return _AddressThree;}
        }

        public string City
        {
            get { return _City; }
        }

        public string State
        {
            get { return _State;}
        }

        public string ZipCode
        {
            get { return _ZipCode;}
        }

        public Address(string name,AddressType type,string addressOne,
            string addressTwo,string addressThree, 
            string city,string state,string zipcode)
        {
            _Name = name;
            _Type = type;
            _AddressOne = addressOne;
            _AddressTwo = addressTwo;
            _AddressThree = addressThree;
            _City = city;
            _State = state;
            _ZipCode = zipcode;
        }

    

    }

    public class Addresses
    {




    }

    public enum EmailType
    {
        Work,
        Home,
        Family
    }

    public class EmailAddress
    {
        private string _EmailAddress;
        private EmailType _Type;

        public string Email
        {
            get { return _EmailAddress; }
        }
        public EmailType Type
        {
            get { return _Type; }
        }

        public EmailAddress(string emailAddress,EmailType Type)
        {
            _EmailAddress = emailAddress;
            _Type = Type;
        }
        
        public string ToString()
        {
            return _EmailAddress;
        }
    }

    public class EmailAddresses
    {
        
    }

    public enum PhoneType
    {
        Home,
        Work,
        Cell,
        Other
    }

    public class PhoneNumber
    {
        private PhoneType _Type;
        private string _Number;

        public PhoneType Type
        {
            get { return _Type; }
        }
        public string Number
        {
            get { return _Number; }
        }

        public PhoneNumber(PhoneType phoneType, string phonenumber)
        {
            _Type = phoneType;
            _Number = phonenumber;
        }
    }

    public class PhoneNumbers
    {

    }

    public class Golfer
    {
        /*
         * The GolferID property may not necessarily be populated with a GUID
         * yet.  The reason is that it hasn't been saved yet.
         * 
         * */
        private Guid _GolferID;
        private string _FirstName;
        private string _LastName;
        private Addresses _Addresses;
        private EmailAddresses _Emails;
        private PhoneNumbers _PhoneNumbers;

        public Guid GolferID
        {
            get { return _GolferID; }
        }
        public string FirstName
        {
            get
            {
                return _FirstName;
            }
        }
        public string LastName
        {
            get
            {return _LastName;}
        }
        public Addresses GolferAddresses
        {
            get { return _Addresses; }
        }
        public EmailAddresses Emails
        {
            get { return _Emails; }
        }
        public PhoneNumbers PhoneNums
        {
            get { return _PhoneNumbers; }
        }

        public Golfer(string firstname, string lastname, Addresses addresses,
                EmailAddresses emails, PhoneNumbers phonenumbers)
        {
            _FirstName = firstname;
            _LastName = lastname;
            _Addresses = addresses;
            _Emails = emails;
            _PhoneNumbers = phonenumbers;
        }

        public void Save()
        {
            //This will save the golfer to the database that you choose.
            if (_GolferID == null)
            {

            }
            else
            {

            }

        }

    }

    public class GolfCourse
    {
        private PhoneNumbers _PhoneNumbers;
        private Addresses _Addresses;
        private SubCourses _SubCourses;

        public Addresses addresses
        {
            get {return _Addresses; }
        }

        public PhoneNumbers phonenumbers
        {
            get { return _PhoneNumbers; }
        }

        public SubCourses subcourses
        {
            get { return _SubCourses; }
        }
   
        public GolfCourse(Addresses addresses,PhoneNumbers phonenumbers,
            SubCourses subcourses)
        {
            _Addresses = addresses;
            _PhoneNumbers = phonenumbers;
            _SubCourses = subcourses;
        }

    }

    public class SubCourse
    {

    }

    public class SubCourses
    {

    }

    public class GolfScore
    {


    }

    public class RegistryGSA
    {
        bool _MaxNewForms;

        public bool MaxNewForms
        {
            get {return _MaxNewForms;}
        }

        public RegistryGSA()
        {
            FirstTimeLoadCheck();
            LoadVariables();
        }

        private void LoadVariables()
        {
            RegistryKey key = Registry.CurrentUser;
            RegistryKey SettingsKey = key.OpenSubKey(@"Software\WebandNetwork\Settings");
            string strMaxNewWindows = (string)SettingsKey.GetValue("MaxNewWindows");
            if (strMaxNewWindows == "false")
            {
                _MaxNewForms = false;
            }
            else
            {
                _MaxNewForms = true;
            }



        }

        public void Refresh()
        {
            LoadVariables();
        }

        private void FirstTimeLoadCheck()
        {
            //If we need to load the new values so the application can work properly.
            RegistryKey key = Registry.CurrentUser;
            RegistryKey SettingsKey;

            key = key.OpenSubKey("Software",true);
            if (!RegKeyFoundbyName(key, "WebandNetwork"))
            {
                key = AddRegistryKey(key, "WebandNetwork");
            }
            else
            {
                key = key.OpenSubKey("WebandNetwork",true);
            }
            //Now Find the Values We need to find. key should equal the root for the app.
            if (!RegKeyFoundbyName(key, "Settings"))
            {
                SettingsKey = AddRegistryKey(key, "Settings");
            }
            else
            {
                SettingsKey = key.OpenSubKey("Settings",true);
            }

            object objMaxNewWindows = SettingsKey.GetValue("MaxNewWindows");
            if (objMaxNewWindows == null)
            {
                SettingsKey.SetValue("MaxNewWindows", "true", RegistryValueKind.String);
            }

            key.Close();
            SettingsKey.Close();
        }

        private bool RegKeyFoundbyName(RegistryKey key, string Name)
        {
            bool blReturnValue = false;
            foreach (string strKey in key.GetSubKeyNames())
            {
                if (strKey == Name)
                {
                    blReturnValue = true;
                }
            }
            return blReturnValue;
        }
        
        private RegistryKey AddRegistryKey(RegistryKey key,string Name)
        {
            RegistryKey rkReturn;
            rkReturn = key.CreateSubKey(Name, RegistryKeyPermissionCheck.ReadWriteSubTree);
            return rkReturn;
        }



    }


    public class SQLServer
    {
        private string _name;
        private string _ServerName;
        private string _connectionstring;
        private string _DatabaseName;
        private string _UserName;
        private string _Password;
        private SqlConnection _sqlConnection;
        private bool IntegratedSecurity;

        public string Name
        {
            get { return _name; }
        }
        public string ServerName
        {
            get { return _ServerName; }
        }
        public string ConnectionString
        {
            get { return _connectionstring; }
        }
        public string DatabaseName
        {
            get { return _DatabaseName; }
        }
        public string Username
        {
            get { return _UserName; }
        }
        public string Password
        {
            get { return _Password; }
        }
        

        public SQLServer(string name, string servername, string databasename, 
            string username, string password)
        {
            //This creates the connection string. 
            _name = name;
            _ServerName = servername;
            _DatabaseName = databasename;
            _UserName = username;
            _Password = password;
            IntegratedSecurity = false;
        }

        public SQLServer(string name, string servername, string databasename)
        {
            //This creates the connection string using integrated security. 
            //Data Source=BAD\SQLEXPRESS;Initial Catalog=GSA;Integrated Security=True
            _name = name;
            _ServerName = servername;
            _DatabaseName = databasename;
            _connectionstring = @"Data Source=" + servername + ";Initial Catalog=" + databasename + ";Integrated Security=True";
            IntegratedSecurity = true;
        }

        public SQLServer(string name,string connectionstring)
        {
            //this only populates the connection string as an override
            _name = name;
            _connectionstring = connectionstring;
        }

        private void Connect()
        {
            try
            {
                _sqlConnection = new SqlConnection(_connectionstring);
                _sqlConnection.Open();
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
    }

}
